<?php
class AuthController extends Core_Controller_Action {
    
    public function indexAction() {
        if ($this->getRequest()->isPost()) {
            $this->setAjaxCall();

            $user_name = $this->_getParam("username");
            $password = $this->_getParam("password");
            $user_db = new Core_Model_DbTable_Users();
            $user = $user_db->login($user_name, $password);
            if ($user) {
                if ($this->_getParam("remember_me")) {
                    Core_Util::rememberMe();
                }
                $session = $this->session;
                $session->user = $user;            
                $this->_helper->redirector->goToUrl("/");
            } else {
                $this->redirect("/auth");
            }
        }
    }
    
    public function logoutAction() {
        $session = $this->session;
        $session->user = NULL;
        Zend_Session::forgetMe();
        $this->_helper->redirector->goToUrl("/");
    }
}
?>
